package com.hantang.web.config;

import java.io.File;
import java.io.FileInputStream;
import java.io.InputStream;
import java.util.Properties;

import org.apache.log4j.Logger;

public class JsonConfig {

	private static Logger logger = Logger.getLogger(JsonConfig.class);
	
	private static JsonConfig instance = new JsonConfig();
	public final static String configPath = "/config/JsonConfiguration.properties"; 
	public static JsonConfig getInstance()
	{
		return instance;
	}
	private JsonConfig(){
		this.init();
	};
	
	private int port;
	
	public int articleInfoContentSize = 20;
 
	
	private static Properties properties;
	//corePoolSize=80
	//maxiumPoolSize=150
	private int corePoolSize = 20;
	private int maxiumPoolSize = 100;
	

    public static Properties getProperties(String config) {
        Properties properties = new Properties();
        InputStream is = null;
        try {
            File f = new File(config);
            if (f.isFile()) {
                is = new FileInputStream(f);
            } else {
                //Try the class stream loader
                is = JsonConfig.class.getResourceAsStream(config);
            }
            if (is != null) {
                properties.load(is);
                //properties.list(System.out);
            }
        } catch (Exception e) {
        } finally {
            if (is != null) {
                try {
                    is.close();
                } catch (Exception e) {
                }
            }
        }

        return properties;
    }
    
	private void init()
	{
		String tmp;
		properties = getProperties(configPath);
		
		tmp = properties.getProperty("port");
		if(tmp != null)
		{
			this.port = Integer.valueOf(tmp.trim());
		}
		if(tmp!=null)
		{
			this.corePoolSize = Integer.parseInt(tmp);
		}
		logger.info("corePoolSize:" + corePoolSize);
		tmp = properties.getProperty("maxiumPoolSize");
		if(tmp!=null)
		{
			this.maxiumPoolSize = Integer.parseInt(tmp);
		}
		logger.info("maxiumPoolSize:" + maxiumPoolSize);		
	}
 
	public int getPort() {
		return port;
	}

 
	public int getCorePoolSize() {
		return corePoolSize;
	}
	public void setCorePoolSize(int corePoolSize) {
		this.corePoolSize = corePoolSize;
	}
	public int getMaxiumPoolSize() {
		return maxiumPoolSize;
	}
	public void setMaxiumPoolSize(int maxiumPoolSize) {
		this.maxiumPoolSize = maxiumPoolSize;
	}
	public static String getProperty(String key)
    {
    	return properties.getProperty(key);
    }
}
